package com.xyy.saas.payment.pojo.param;

import com.xyy.saas.payment.dao.model.SeparateOrder;
import com.xyy.saas.payment.util.AmountCastUtil;
import com.xyy.saas.payment.util.ApolloUtil;
import com.xyy.saas.payment.util.DateUtil;
import lombok.Data;

import java.util.Objects;

@Data
public class AccountTransferVO {
    /**
     * 出账方
     */
    private String outAccountName;
    /**
     * 入账方
     */
    private String inAccountName;
    /**
     * 金额
     */
    private String amount;
    /**
     * 状态
     */
    private String status;
    /**
     * 创建时间
     */
    private String createTime;
    /**
     * 备注
     */
    private String remark;

    public static AccountTransferVO transfer(SeparateOrder separateOrder) {
        AccountTransferVO item = new AccountTransferVO();
        item.setOutAccountName(getAccountName(separateOrder.getCustMerchant()));
        item.setInAccountName(getAccountName(separateOrder.getCustNoIn()));
        item.setAmount(AmountCastUtil.castFen2Yuan(separateOrder.getTradeAmount()));

        if(SeparateOrder.STATUS_FINISH.equals(separateOrder.getStatus())) {
            item.setStatus("成功");
        }
        else {
            item.setStatus("失败");
        }

        item.setCreateTime(DateUtil.format(separateOrder.getCtime(), DateUtil.DATEFORMATSECOND));
        item.setRemark(separateOrder.getExtra());
        return item;
    }

    public static String getAccountName(String accountId) {
        if(Objects.equals(accountId, ApolloUtil.getProperty("ec_pingan_summary_account_id"))) {
            return "平台挂帐子账户";
        }

        if(Objects.equals(accountId, ApolloUtil.getProperty("ec_pingan_refund_account_id"))) {
            return "平台退款垫资户";
        }

        if(Objects.equals(accountId, ApolloUtil.getProperty("ec_pingan_balance_account_id"))) {
            return "平台购物金户";
        }

        if(Objects.equals(accountId, ApolloUtil.getProperty("ec_pingan_market_account_id"))) {
            return "平台营销补贴户";
        }

        if(Objects.equals(accountId, ApolloUtil.getProperty("ec_pingan_out_brokerage_account_id"))) {
            return "平台退佣金户";
        }

        if(Objects.equals(accountId, ApolloUtil.getProperty("ec_pingan_in_brokerage_account_id"))) {
            return "平台收佣金户（含退回补贴/购物金）";
        }

        if(Objects.equals(accountId, ApolloUtil.getProperty("ec_pingan_platform_aggr_withdraw_account_id"))) {
            return "平台提现专用户";
        }

        return "位置账户";
    }
}
